package org.jypj.dev.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.jypj.dev.cache.PicSettingCache;
import org.jypj.dev.dao.ISettingDao;
import org.jypj.dev.model.Setting;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "picSettingController")
public class PicSettingController extends BaseController {

    @Resource
    private ISettingDao settingDao;

    /**
     * 进入登录页面
     *
     * @return
     */
    @RequestMapping(value = "/toPicSetting.action")
    public String toPicSetting(HttpServletRequest request) {
        request.setAttribute("setting", getSetting());
        return "back/sys/pic_setting";
    }

    /**
     * 更新帮助文档
     * @param contentHtml
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "updatePicSetting.action")
    public Map<String, Object> updatePicSetting(String contentHtml) {
        Map<String, Object> dataMap = new HashMap<>();
        int code = 0;
        try {
            Setting setting = getSetting();
            setting.setApp_help(contentHtml);
            System.out.println(setting);
            settingDao.updateSetting(setting);
        } catch (Exception e) {
            e.printStackTrace();
            code = -1;
        }
        dataMap.put("code", code);
        return dataMap;
    }
}
